﻿using Vin.Extension.Redis.Cache;
using Vin.Tool.Core.DateTimeCategory;

namespace Vin.Extension.Framework.Tools;

public class DateNumberGenerateTool
{
    public const string GenerateRedisKey = "DateNumberIncrKey";

    /// <summary>
    /// 生层订单号
    /// </summary>
    /// <returns></returns>
    public static async Task<string> GenerateDateNumberPadLeftAsync(int padCount = 4, char padChar = '0')
    {
        var now = DateTime.Now;
        var num = await RedisCacheManager.GetRedisCache()
            .IncrAsync(GenerateRedisKey + now.ToTimestamp(false), TimeSpan.FromSeconds(2));
        return now.ToString("yyyyMMddHHmmss") + num.ToString().PadLeft(padCount, padChar);
    }
}